home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Digital Editor Plugs / FadeVol.c < prev    next >
C/C++ Source or Header  |  1995-09-23  |  4KB  |  171 lines

  1. /*    Fade In Vol        */
  2. /*    v 1.0            */
  3. /*    1995 by ANR        */
  4.  
  5. //    Usage:
  6. //    A small example of to use Digital Editor Plugs with a MODAL DIALOG
  7.  
  8. #include "MAD.h"
  9. #include "PPPlug.h"
  10.  
  11. #if defined(powerc) || defined(__powerc)
  12. enum {
  13.         PlayerPROPlug = kCStackBased
  14.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  15.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
  16.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
  17. };
  18.  
  19. ProcInfoType __procinfo = PlayerPROPlug;
  20. #else
  21. #include <A4Stuff.h>
  22. #endif
  23.  
  24. void GetDText (DialogPtr dlog, short item, StringPtr str)
  25. {
  26. Handle    itemHandle;
  27. short    itemType;
  28. Rect    itemRect;
  29.  
  30.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  31.     GetIText (itemHandle, str);
  32. }
  33.  
  34. void SetDText (DialogPtr dlog, short item, Str255 str)
  35. {
  36. Handle    itemHandle;
  37. short    itemType;
  38. Rect    itemRect;
  39.  
  40.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  41.     SetIText (itemHandle, str);
  42. }
  43.  
  44. GDHandle    TheGDevice:0xCC8;
  45.  
  46. void AutoPosition( DialogPtr aDia)
  47. {
  48.     Point    Position, mouse;
  49.     Rect    ViewRect;
  50.     short    XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
  51.     
  52.     GetMouse( &mouse);
  53.     LocalToGlobal( &mouse);
  54.     
  55.     SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
  56.                         (*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
  57.     
  58.     Position.h = mouse.h - XSize/2;
  59.     if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
  60.     else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
  61.     
  62.     Position.v = mouse.v - YSize/2;
  63.     if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
  64.     else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
  65.     
  66.     MoveWindow( aDia, Position.h, Position.v, false);
  67.     
  68.     ShowWindow( aDia);
  69. }
  70.  
  71. Cmd* GetCmd( short row, short    track, Pcmd*    myPcmd)
  72. {
  73.     if( row < 0) row = 0;
  74.     else if( row >= myPcmd->length) row = myPcmd->length -1;
  75.  
  76.     if( track < 0) track = 0;
  77.     else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
  78.     
  79.     return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
  80. }
  81.  
  82. OSErr main(     Pcmd                    *myPcmd,
  83.                 PPInfoPlug                *thePPInfoPlug)
  84. {
  85.     DialogPtr            myDia;
  86.     short                itemHit;
  87.     Str255                tStr;
  88.     
  89. #ifndef powerc
  90.     long    oldA4 = SetCurrentA4();             //this call is necessary for strings in 68k code resources
  91. #endif
  92.  
  93.     myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
  94.     SetPort( myDia);
  95.     AutoPosition( myDia);
  96.  
  97.     SetDText( myDia, 3, "\p0");
  98.     SetDText( myDia, 4, "\p100");
  99.     SelIText( myDia, 3, 0, 200);
  100.     
  101.     do
  102.     {
  103.         RESTART:
  104.     
  105.         #if defined(powerc) || defined(__powerc)
  106.         ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  107.         #else
  108.         ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  109.         #endif
  110.         
  111.     }while( itemHit != 1 && itemHit != 2);
  112.     
  113.     if( itemHit == 1)
  114.     {
  115.         short    track, row;
  116.         long    from, to;
  117.         Cmd        *myCmd;
  118.     
  119.         GetDText( myDia, 3, tStr);        StringToNum( tStr, &from);
  120.         GetDText( myDia, 4, tStr);        StringToNum( tStr, &to);
  121.         
  122.         // Check values
  123.         
  124.         if( from < 0 || from > 100)
  125.         {
  126.             SelIText( myDia, 3, 0, 200);
  127.             SysBeep( 1);
  128.             goto RESTART;
  129.         }
  130.         
  131.         if( to < 0 || to > 100)
  132.         {
  133.             SelIText( myDia, 4, 0, 200);
  134.             SysBeep( 1);
  135.             goto RESTART;
  136.         }
  137.         
  138.         // Re-adjust val % -> 0...64
  139.         
  140.         to         = (to * 64) / 100;
  141.         from     = (from * 64) / 100;
  142.         
  143.         for( track = 0; track < myPcmd->tracks; track++)
  144.         {
  145.             for( row = 0; row < myPcmd->length; row++)
  146.             {
  147.                 myCmd = GetCmd( row, track, myPcmd);
  148.             
  149.                 myCmd->ins     = myCmd->ins;        // is this very usefull ?
  150.                 myCmd->note    = myCmd->note;        // is this very usefull ?
  151.                 myCmd->cmd    = myCmd->cmd;        // is this very usefull ?
  152.                 myCmd->arg    = myCmd->arg;        // is this very usefull ?
  153.                 
  154.                 if( myPcmd->length > 1)            // no zero div !!
  155.                     myCmd->vol    = 0x10 + from + ((to-from) * row) / (myPcmd->length-1);
  156.                 
  157.                 // my fade command : 0x10 min vol, 0x50 : max vol
  158.                 // Refer to MAD description for more informations            
  159.             }
  160.         }
  161.     }
  162.     
  163.     DisposDialog( myDia);
  164.     
  165.     #ifndef powerc
  166.         SetA4( oldA4);
  167.     #endif
  168.  
  169.     
  170.     return noErr;
  171. }